<template>
   <view class="category-container">
    <view class="banner-cover-img">
      <image class="banner-img" src="/static/images/category_bg.png"></image>
    </view>
    <view class="category-title">
      <SectionMoreLine :isMore="false" :title="'栏目分类'" />
    </view>

    <view class="category-list">
      <view
        class="category-item"
        v-for="item in categoryList"
        :key="item.id"
        @click="goCategoryVideo(item.id, item.name)"
      >
        <view class="cover-img">
          <image
            class="preview-img"
            :src="item.home_image"
          ></image>
        </view>
        <view class="position-row">
          <text class="category-text">{{item.name}}</text>
          <text class="video-count">共{{item.video_count}}部</text>
        </view>
        <view class="bg"></view>
      </view>
    </view>
  </view>
</template>

<script>
import * as api from '@/api/api';
export default {
  name: "category",
  components: {},
  data() {
    return {
      categoryList: []
    };
  },
  onLoad() {
    this.getCategories();
  },
  mounted() {},
  methods: {
    async getCategories() {
      const {data: res} = await api.getCategories();
      this.categoryList = res.data;
    },
    goCategoryVideo(cateId, name) {
      uni.navigateTo({url: `/pages/category/category_video?cateId=${cateId}&name=${name}`});
    }
  }
};
</script>
<style lang="scss" scoped>
.category-container {
  width: 100%;
  min-height: 100vh;
  .banner-cover-img {
    width: 100%;
    height: 300rpx;
    .banner-img {
      width: 100%;
      height: 100%;
    }
  }
  .category-title {
    margin: 30rpx 0;
    padding-left: 30rpx;
  }
  .category-list {
    margin: 20rpx auto 0;
    width: 690rpx;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    .category-item {
      width: 335rpx;
      height: 180rpx;
      position: relative;
      overflow: hidden;
      margin-bottom: 20rpx;
      border-radius: 10rpx;
      .cover-img {
        width: 100%;
        height: 100%;
        .preview-img {
          width: 100%;
          height: 100%;
        }
      }
      .position-row {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        z-index: 99;
        display: inline-flex;
        flex-direction: column;
        align-items: center;
      }
      .category-text {
        font-size: 36rpx;
        color: #fff;
      }
      .video-count {
        font-size: 22rpx;
        color: #fff;
        margin-top: 8rpx;
      }
      .bg {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        background-color: #000;
        opacity: 0.5;
      }
    }
  }
}
</style>